

package GUI;
/**
 * principles view student personal data screen
 */

import java.awt.Dimension;
import java.util.Vector;

import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.JComboBox;
import javax.swing.JButton;
import Common.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;


public class ParentViewPersonalData extends JPanel {

	private JLabel lblViewPersonalData=null;
	private JLabel lblSelectYear=null;
	private JLabel lblSelectCourse=null;
	private JLabel lblSelectSemester=null;
	private JComboBox comboBoxSelSemester=null;
	private JComboBox comboBoxSelYear=null; 
	private JComboBox comboBoxSelCourse=null;
	private JButton btnShowData=null;
	public Dimension defaultDim = null;
	public Login myLoginFrame = null;
	public UserParent user=null;
	public ParentMainMenu pmn=null;
	public ParentViewPersonalData pViewPD=null;
	private Vector<String> courseDetails=null;
	private JButton btnViewCheckedAssignments = null;
	private ParentViewCheckedAssignmentScreen viewCheckedAssignmentScr=null;
	
	
	public Vector<StudentClass> data=null;
	private int i=0;
	private ShowDataScreenParent dataScreen=null;

	public JButton getViewCheckedAssignmentsButton()
	{
		if (btnViewCheckedAssignments==null)
		{
			
			 btnViewCheckedAssignments = new JButton("View checked assignments");
			
			 btnViewCheckedAssignments.addActionListener(new ActionListener() {
			 	public void actionPerformed(ActionEvent arg0) {
			 		btnViewCheckedAssignments=null;
			 		pmn.user.SetSemester(comboBoxSelSemester.getSelectedItem().toString());
			 		pmn.user.SetYear(comboBoxSelYear.getSelectedItem().toString());
			 		pmn.user.SetCourse(comboBoxSelCourse.getSelectedItem().toString());
			 		System.out.println("ALON" + pmn.user.getYear() + " " +pmn.user.getCourse() +" " +pmn.user.getSem() );
			 		viewCheckedAssignmentScr = null;
			 		viewCheckedAssignmentScr=pmn.getCheckedAssignmentScr();
			 		
			 		
			 		
			 		pmn.setContentPane(viewCheckedAssignmentScr);
			 	}
			 });
			 btnViewCheckedAssignments.setBounds(326, 359, 161, 23);
			//TODO add action listener
			
		}
		return btnViewCheckedAssignments;
	}	
	
	
	public JButton getShowDataButton()
	{
		if (btnShowData==null)
		{
			 btnShowData = new JButton("Show Data");
			 btnShowData.addActionListener(new ActionListener() {
			 	public void actionPerformed(ActionEvent arg0) {
			 		dataScreen=null;
			 		pmn.user.SetSemester(comboBoxSelSemester.getSelectedItem().toString());
			 		pmn.user.SetYear(comboBoxSelYear.getSelectedItem().toString());
			 		pmn.user.SetCourse(comboBoxSelCourse.getSelectedItem().toString());
			 		System.out.println("ALON" + pmn.user.getYear() + " " +pmn.user.getCourse() +" " +pmn.user.getSem() );
			 		
			 		dataScreen=getShowDataScreen();
			 		
			 		
			 		
			 		pmn.setContentPane(dataScreen);
			 	}
			 });
			 btnShowData.setBounds(326, 301, 124, 23);
			//TODO add action listener
			
		}
		return btnShowData;
	}
	
	private void initialize(ParentMainMenu pmn)
	{
	 setLayout(null);
	 lblViewPersonalData = new JLabel("Parental view student info");
   	 lblViewPersonalData.setBounds(163, 11, 189, 19);
	
   	 lblSelectYear = new JLabel("Select Year:");
   	 lblSelectYear.setBounds(25, 120, 82, 14);
   	 
     lblSelectSemester = new JLabel("Select Semester:");
	 lblSelectSemester.setBounds(25, 183, 82, 14);
	 
	 lblSelectCourse = new JLabel("Select Course:");
	 lblSelectCourse.setBounds(25, 246, 82, 14);
	 
	
	 
	
	 this.add(lblViewPersonalData);
	 this.add(lblSelectYear);
	 this.add(lblSelectSemester);
	 this.add(lblSelectCourse);
	 
	 
	 this.add(getShowDataButton());

	
	 
	 i=getData(pmn);
	 this.pmn=pmn;
	 
	 this.add(getComboBoxSelYear(i));
	 this.add(getComboBoxSelSemester(i));
	 this.add(getComboBoxSelCourse(i));
	 this.add(getViewCheckedAssignmentsButton());
	 
	
	 
	  
	}
	


	public JComboBox getComboBoxSelYear(int i)
	{
	    
		 if(comboBoxSelYear==null)
		{
		System.out.println("Alon:"+ i);
		System.out.println(pmn.user.StudentsData.get(i).FirstName);
		System.out.println(pmn.user.StudentsData.get(i).Years);
		
		comboBoxSelYear	= new JComboBox(pmn.user.StudentsData.get(i).Years);
		comboBoxSelYear.setBounds(150, 120, 159, 22);
	
		//TODO add available years to this student
		}
		return comboBoxSelYear;
	}
	
	
	
	public JComboBox getComboBoxSelSemester(int i)
	{
		if(comboBoxSelSemester==null)
		{
		comboBoxSelSemester = new JComboBox(pmn.user.StudentsData.get(i).Semesters);
		comboBoxSelSemester.setBounds(150, 179, 158, 22);
		
		//TODO add available semesters the year selected above for this student
		}
	
		return comboBoxSelSemester;
		
	}
	
	public JComboBox getComboBoxSelCourse(int i)
	{
		courseDetails = new Vector<String>();
		
		for(int j=0;j<pmn.user.StudentsData.get(i).ListOfCourses.lOfCourses.size();j++)
		{
		
			
			System.out.println("Course name "+pmn.user.StudentsData.get(i).ListOfCourses.lOfCourses.get(j).getCname());
			System.out.println("Course ID "+pmn.user.StudentsData.get(i).ListOfCourses.lOfCourses.get(j).getCid().toString());
			courseDetails.addElement(pmn.user.StudentsData.get(i).ListOfCourses.lOfCourses.get(j).getCname()+ " " + pmn.user.StudentsData.get(i).ListOfCourses.lOfCourses.get(j).getCid().toString());
		}
			
		if(comboBoxSelCourse==null)
		{
			comboBoxSelCourse = new JComboBox(courseDetails);
			comboBoxSelCourse.setBounds(150, 238, 158, 22);
			//TODO add available courses for the selected semester above for the year selected above for this student
		}
		return comboBoxSelCourse;
	}
	
	private int getData(ParentMainMenu pmn)
	{
		int i;
		
				
		for(i=0;i<pmn.user.StudentsData.size();i++)
		
		{
			System.out.println(pmn.user.StudentsData.get(i).Sid);
			System.out.println("GetName" + pmn.user.GetName());
			
			if(pmn.user.GetName().endsWith(pmn.user.StudentsData.get(i).Sid.toString()))
			 {
				 data = new Vector<StudentClass>();
			 	data.add(pmn.user.StudentsData.get(i));
			 	pmn.user.setIndex(i);
			 	break;
			 }
		 }
		return i;
		 
	}
	public ShowDataScreenParent getShowDataScreen()
	{
	
		
		if(dataScreen==null)
		{
			
			dataScreen=new ShowDataScreenParent(pmn.user.StudentsData.get(i),pmn);
			dataScreen.setSize(getMaximumSize());
		//	dataScreen.setParentMainMenu(pmn);
			
		
			
		}
		return dataScreen;
	}

	

	
	
	
	public ParentViewPersonalData(ParentMainMenu pmn) {
		super();
		initialize(pmn);

	}
	

}
